<CFIF not isDefined("session.tablocation")>
	<CFSET session.tablocation="../">
</CFIF>
<!---
<script>
function ShowCalendar(FormName, FieldName) {
		quickpopdate(FormName, FieldName)
	}
</script>
--->
<CFSET sMess   = "">
<CFSET sWarn   = "">

<CFSETTING ENABLECFOUTPUTONLY="Yes">

<!--------------------------------------------------->
<!--- Module: eForm								  --->
<!--- Description: uses the personnelidno as main --->
<!---   index and allows 5 indices at most		  --->
<!--- Updated by: Rence							  --->
<!--- Last Update: 03/14/2001 1704H				  --->
<!--------------------------------------------------->

<CFIF IsDefined("url.typeid")>
	<CFSET eform.sender	= "#getfileFromPath(getBaseTemplatePath())#?id=#URLEncodedFormat(encrypt(url.typeid, client.ek))#">
	<CFSET eform.senderURLs	= "id=#URLEncodedFormat(encrypt(url.typeid, client.ek))#">
	<CFSET sTypeID      = url.typeid>
	<CFSET sMess=url.sendmess>
<CFELSEIF ParameterExists(url.id)>
	<CFTRY>
		<CFSET eform.sender	= "#getfileFromPath(getBaseTemplatePath())#?id=#URLEncodedFormat(url.id)#">
		<CFSET eform.senderURLs	= "id=#URLEncodedFormat(url.id)#">
		<CFSET sTypeID      = decrypt(url.id, client.ek)>
		<CFCATCH>
			<CFOUTPUT>#CFCATCH.message# #CFCATCH.DETAIL#</CFOUTPUT>
		</CFCATCH>
	</CFTRY>
<CFELSE>
	<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ERR_PARAM">
</CFIF>

<cfset pidno = "">

<!--- url for Personnel ID No. --->
<cfif structkeyexists(url, "PERSONNELIDNO")>
	<cfset pidno = url.PERSONNELIDNO>
<cfelseif structkeyexists(Form, "myPID")>
	<cfset pidno = Form.myPID>
<cfelseif structkeyexists(url, "pid")>
	<cfset pidno = url.pid>
<cfelseif structkeyexists(form, "hdpid")>
	<cfset pidno = Form.hdpid>
<cfelse>
	<cfset pidno = client.chapa>
</cfif>

<!--- sending email using MAPI mail-transport --->
<CFIF isDefined("Form.Send") AND client.mailserver NEQ "">
	<CFINCLUDE TEMPLATE="#client.common_path#sendtoMAPI.cfm">
</CFIF>

<!--- get the employee --->
<!---
<CFQUERY NAME="GetEmployee" DATASOURCE="#client.company_dsn#" MAXROWS=1>
  SELECT PERSONNELIDNO, LASTNAME, FIRSTNAME
	FROM CMFPA
	WHERE	(GUID = '#client.guid#')
</CFQUERY>
--->


<cfquery name="getDBNameG" datasource="#client.global_dsn#">
	SELECT B.DATABASENAME FROM EGRGCOMPANYSETTINGS A, GRGDATALOCATION B
	WHERE A.COMPANYCODE = '#client.companycode#'
	AND A.DLCVARIABLE = B.DATALOCATIONCODE
</cfquery>

<cfquery name="getDBNameC" datasource="#client.global_dsn#">
	SELECT B.DATABASENAME FROM GRGCOMPANY A, GRGDATALOCATION B
	WHERE A.COMPANYCODE = '#client.companycode#'
	AND A.DATALOCATIONCODE = B.DATALOCATIONCODE
</cfquery>

<cfquery name="GetUserInfo" datasource="#client.global_dsn#">
	SELECT USERID, GUID FROM EGRGUSERMASTER
	WHERE GUID IN (SELECT GUID FROM #getDBNameC.DATABASENAME#.[dbo].CMFPA 
			WHERE PERSONNELIDNO = '#pidno#')
</cfquery>

<CFQUERY NAME="GetEmployee" DATASOURCE="#client.company_dsn#" MAXROWS=1>
  SELECT PERSONNELIDNO, LASTNAME, FIRSTNAME
	FROM CMFPA
	WHERE	(GUID = '#GetUserInfo.GUID#')
</CFQUERY>

<CFIF NOT(GetEmployee.RecordCount)>
	<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ERR_EMPLOYEE">
</CFIF>

<!--- check if user has access to the form --->
<CFSET sRightID = "">
<!---
<CFINCLUDE TEMPLATE="../common/_validate.cfm">
<CFIF sRightID EQ "">
	<CFLOCATION URL="../common/norights.cfm" ADDTOKEN="No">
</CFIF>
--->



<cfquery name="getGroupAccess" datasource="#client.company_dsn#">
	SELECT USERGRPID_FK FROM ECRTFORMS
	WHERE USERGRPID_FK IN (SELECT USERGRPID_FK FROM #getDBNameG.DATABASENAME#.[dbo].EGLNUSERGROUPS
				WHERE USERGRPMEMBERS = '#GetUserInfo.USERID#')
	AND FORMCODE_FK = '#sTypeID#'
</cfquery>

<cfloop query="getGroupAccess">
	<cfset sRightID = listAppend(sRightID, "'#USERGRPID_FK#'", ",")>
</cfloop>

<cfquery name="getUserAccess" datasource="#client.company_dsn#">
	SELECT USERGRPID_FK FROM ECRTFORMS
	WHERE USERGRPID_FK = '#GetUserInfo.USERID#'
	AND FORMCODE_FK = '#sTypeID#'
</cfquery>

<cfloop query="getUserAccess">
	<cfset sRightID = listAppend(sRightID, "'#USERGRPID_FK#'", ",")>
</cfloop>


<cfinvoke component="getform"  method="GetTheForm" returnvariable="GetForm">
	<cfinvokeargument name="rightID" value="#sRightID#">
	<cfinvokeargument name="typeID" value="#sTypeID#">
	<cfinvokeargument name="tDSN" value="#client.company_dsn#">
</cfinvoke>
<!--- get for form details --->
<!---
<CFQUERY NAME="GetForm" DATASOURCE="#client.company_dsn#">
	SELECT 
		<!--- E.*, --->
		E.FORMCODE, E.FORMGROUP, E.FORMTYPE, E.DESCRIPTION, E.PREPROCESSPROMPT, E.PREPROMPTMPLATE, E.PREUP2RCPTLEVEL,E.ENABLEBATCHAPPLY,
		E.TABLENAME_FK, E.PK_FIELD1, E.PK_FIELD2, E.PK_FIELD3,
		E.PK_FIELD4, E.PK_FIELD5, E.TEMPLATECODE_FK, E.ICONNAME,
		E.PROCESSCODE, E.RECORDFILTER, E.CALENDARFIELD,
		E.MASTERDETAIL, E.PREPROCESS, E.PREPROCESSTITLE,
		E.DEFAULTORDER, E.DEFAULTASCDESC, E.PREPROMPTTITLE,
		E.COPYTOFORMCODE, E.FLDFORLATEAPPS, E.GRACEPRDLATEAPPS,
		E.LATEAPPSMODE, E.ENABLEATTACHMENTS,E.ENABLEMAILAPPROV,E.ATTACHEDMAIL,E.ATTACHEDLINK,
		E1.ISADD, E1.ISEDIT, E1.ISDELETE, E1.ISVIEW, E1.ISEMAIL,E1.ISPRINT,E.ENABLEGROUPROUTE,E.MULTIPLEFORMFLOW,E1.BATCHAPPLY
	FROM ECRGFORMS E, ECRTFORMS E1
	WHERE
		(E1.USERGRPID_FK IN (#preserveSingleQuotes(sRightID)#)) AND
		(E1.FORMCODE_FK  = E.FORMCODE) AND
		(E1.FORMCODE_FK  = '#sTypeID#')
</CFQUERY>
--->
<!--- by Maan: Get Infocard(s) --->
<!---
<CFQUERY NAME="GetFormDtl" DATASOURCE="#client.company_dsn#">
	SELECT E2.*
	FROM ECRGFORMS E, ECRTFORMS E1, ECRGFORMSDETAIL E2
	WHERE
		(E1.USERGRPID_FK IN (#preserveSingleQuotes(sRightID)#)) AND
		(E1.FORMCODE_FK  = E2.FORMCODE) AND (E.FORMCODE = E2.FORMCODE) AND
		(E1.FORMCODE_FK  = '#sTypeID#')
		ORDER BY E2.SORTID ASC, E2.DESCRIPTION ASC
</CFQUERY>
--->
<CFSET sListPrimary = "">
<CFLOOP FROM="1" TO="5" INDEX="x">
	<!---mico 06252010<CFSET sTmp = Evaluate("GetForm.PK_FIELD#x#")>---><CFSET sTmp = GetForm["PK_FIELD#x#"]>
	<CFIF sTmp NEQ "">
		<CFSET sListPrimary = ListAppend(sListPrimary,sTmp)>
	</CFIF>
</CFLOOP>
<CFQUERY NAME="GetFormDetails" DATASOURCE="#client.company_dsn#">
	SELECT *
	FROM ECRGFORMSDETAIL
	WHERE
		(FORMCODE = '#sTypeID#')
</CFQUERY>

<CFIF NOT(GetForm.RecordCount)>
	<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ERR_TEMPLATE">
</CFIF>


<CFSET accessAdd = 'N'>
<CFSET accessEdit = 'N'>
<CFSET accessDelete = 'N'>
<CFSET accessView = 'N'>
<CFSET accessEmail = 'N'>
<CFSET accessPrint = 'N'>
<CFSET accessBatchApp = 'N'>

<CFLOOP QUERY="GetForm">
	<CFIF GetForm.ISADD EQ 'Y'>
		<CFSET accessAdd = 'Y'>
	</CFIF>
	<CFIF GetForm.ISEDIT EQ 'Y'>
		<CFSET accessEdit = 'Y'>
	</CFIF>
	<CFIF GetForm.ISDELETE EQ 'Y'>
		<CFSET accessDelete = 'Y'>
	</CFIF>
	<CFIF GetForm.ISVIEW EQ 'Y'>
		<CFSET accessView = 'Y'>
	</CFIF>
	<CFIF GetForm.ISEMAIL EQ 'Y'>
		<CFSET accessEmail = 'Y'>
	</CFIF>
	<CFIF GetForm.ISPRINT EQ 'Y'>
		<CFSET accessPrint = 'Y'>
	</CFIF>
	<CFIF GetForm.BATCHAPPLY EQ 'Y'>
		<CFSET accessBatchApp = 'Y'>
	</CFIF>
</CFLOOP>


<CFQUERY NAME="GetLevelID" DATASOURCE="#client.global_dsn#">
	SELECT LEVELID
	FROM GRGBOSETABLE
	WHERE
		(TABLENAME = '#GetForm.TABLENAME_FK#')
</CFQUERY>
<CFIF NOT(GetLevelID.RecordCount)>
	<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ERR_DATA">
</CFIF>

<!--- get table location --->
<!--- custom tag: parameter: DBLEVEL; return value: DSN --->
<CFMODULE TEMPLATE="#client.common_path#cfm_leveldsn.cfm" DBLEVEL="#GetLevelID.LEVELID#">
<CFSET table_dsn = DSN>
<!--- get the fields for the form --->
<CFQUERY NAME="GetFields" DATASOURCE="#client.global_dsn#">
	SELECT *
	FROM GRGBOSETABLEFIELDS
	WHERE
		(TABLENAME  = '#GetForm.TABLENAME_FK#') AND
		(ISVISIBLEEFORM    = 'Y' OR ISVISIBLEEFORM IS NULL) AND
		(COLUMNNAME <> 'PERSONNELIDNO') AND
		(COLUMNNAME <> 'RECDATECREATED') AND
		(COLUMNNAME <> 'RECCREATEDBY') AND
		(COLUMNNAME <> 'USERID') AND
		(COLUMNNAME <> 'DATELASTUPDATE') AND
		(COLUMNNAME <> 'TIMELASTUPDATE') AND
		(COLUMNNAME <> 'ROUTEID') AND
		(COLUMNNAME <> 'APPROVED') AND
		(#sqlSTRLEN#(COLUMNDESC) > 0) AND
<!--- Added by soti to hide additional eforms internal fields --->
		(COLUMNNAME <> 'ATTACHMENTCODE')
		ORDER BY FIELDGROUP, COLUMNORDER, COLUMNDESC, COLUMNNAME
</CFQUERY>
<CFIF GetFields.RecordCount>
	<CFPARAM NAME="eform.field" DEFAULT="#GetFields.COLUMNNAME#">
	<CFSET arrFields = ArrayNew(2)>
	<CFSET tempFld   = "">
	<CFSET iCtr      = 0>
	<CFSET sFields = "">

	<CFOUTPUT QUERY="GetFields">
		<CFPARAM NAME="Form.edt#COLUMNNAME#" DEFAULT="">
		<CFIF lcase(HIDEONBROWSE) NEQ "y" OR len(trim((COLUMNDESC))) NEQ 0>
			<CFSET iCtr = iCtr + 1>
			<CFSET arrFields[iCtr][1] = COLUMNNAME>
			<CFSET arrFields[iCtr][2] = COLUMNDESC>
			<CFSET arrFields[iCtr][3] = COLUMNTYPE>
			<CFSET arrFields[iCtr][4] = HIDEONBROWSE>
			<CFSET arrFields[iCtr][5] = COLUMNREQUIRED>

			<CFIF Lcase(arrFields[iCtr][5]) EQ "y">
				<CFSET nPos = ListFind(sListPrimary,arrFields[iCtr][1])>
				<CFIF nPos NEQ 0>
					<CFSET sListPrimary = ListDeleteAt(sListPrimary,nPos)>
				</CFIF>
			</CFIF>
		</CFIF>
		<CFSET sFields = sFields & "#COLUMNNAME#,">
	</CFOUTPUT>
		<CFSET eform.fieldsarray = arrFields>
</CFIF>

<!--- set default for eform --->

<CFIF Trim(GetForm.DEFAULTORDER) IS "">
	<CFSET sDefaultAscDesc="asc">
<CFELSE>
	<CFSET sDefaultAscDesc=GetForm.DEFAULTASCDESC>
	<CFSET eform.field=GetForm.DEFAULTORDER>
</CFIF>
<CFSET eform.tablename      = GetForm.TABLENAME_FK>
<CFPARAM NAME="eform.locator" DEFAULT="">
<CFPARAM NAME="eform.char"    DEFAULT="all">
<CFPARAM NAME="eform.addnew"  DEFAULT="N">
<CFPARAM NAME="eform.ascdesc" DEFAULT="#sDefaultAscDesc#">
<CFPARAM NAME="form.startrow" DEFAULT=1>


<!--- save current settings --->
<CFIF
	isDefined("Form.First") OR
	isDefined("Form.Prior") OR
	isDefined("Form.Next") OR
	isDefined("Form.Last") OR
	isDefined("Form.Filter")>

	<CFSET eform.field   = Form.cmbSort>
	<CFSET eform.char    = Form.cmbFilter>
	<CFSET eform.locator = Form.edtValFilter>
	<CFSET eform.ascdesc = Form.selAscDesc>
</CFIF>

<!--- selected filter value --->
<CFIF
	isDefined("Form.Sort") OR
	isDefined("Form.Filter")>

	<CFSET form.startrow = 1>
	<CFSET eform.field = Form.cmbSort>
	<CFSET eform.ascdesc = Form.selAscDesc>
</CFIF>

<!--- Check if user access right is invalid, DONT MOVE THIS CODE TO ANOTHER LINE # --->
<!--- Start --->

<!--- get the current record here --->
<CFIF NOT isDefined("form.save") AND NOT isDefined("url.batch")>
	<CFIF (IsDefined("url.edit") AND lcase(accessEdit) EQ "y") OR
		  (IsDefined("url.delete") AND lcase(accessDelete) EQ "y") OR
		  (IsDefined("url.copytoeform") AND GetForm.COPYTOFORMCODE IS NOT "") OR
		  ( (IsDefined("url.sendasemail") OR IsDefined("form.savemail")) AND
		     UCase(Getform.ENABLEATTACHMENTS) IS "Y"
		  )>
	
		<CFQUERY NAME="GetEntry" DATASOURCE="#table_dsn#" MAXROWS=1>
		SELECT *
			FROM #GetForm.TABLENAME_FK#
			WHERE
				(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
				<CFLOOP  INDEX="x" FROM="1" TO="5">
				<!---mico 06252010<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "" AND IsDefined("url." & #evaluate("GetForm.PK_FIELD" & x)#)>--->
				<cfset m = GetForm["PK_FIELD#x#"]>
				<CFIF m NEQ "" AND IsDefined("url." & #evaluate("GetForm.PK_FIELD" & x)#)>
					<CFSET theVal = evaluate("url." & evaluate("GetForm.PK_FIELD" & x))>
					AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
				</CFIF>
				</CFLOOP>
		</CFQUERY>
		<CFSET sAttachMentCode = "#GetEntry.ATTACHMENTCODE#">
	</CFIF>
</CFIF>
<CFIF IsDefined("url.edit")  AND NOT isDefined("url.batch")>
	<CFIF lcase(accessEdit) EQ "y">
		<CFIF NOT(GetEntry.RecordCount)>
			<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
		</CFIF>
		<CFIF (trim(GetEntry.ROUTEID) NEQ "" AND Trim(GetEntry.APPROVED) NEQ "D" AND Trim(GetEntry.APPROVED) NEQ "R" AND Trim(GetEntry.APPROVED) NEQ "B") OR lcase(GetEntry.APPROVED) EQ "y" OR lcase(GetEntry.APPROVED) EQ "C">
			<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
		</CFIF>
		<!---
		<CFIF ListFind("S,Y,N,B,R",UCase(TRIM(GetEntry.APPROVED))) EQ 0>
			<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
		</CFIF>
		--->
	<CFELSE>

		<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
	</CFIF>
</CFIF>


<CFIF IsDefined("url.view") AND NOT isDefined("url.batch")>
	<CFIF lcase(accessEdit) NEQ "y" AND lcase(accessView) NEQ "y">
		<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
	</CFIF>
</CFIF>

<CFIF IsDefined("url.sendasemail")>
	<CFIF lcase(accessEmail) NEQ "y">
		<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
	</CFIF>
</CFIF>

<CFIF IsDefined("url.replicate")>
	<CFIF lcase(accessAdd) NEQ "y">
		<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
	</CFIF>
</CFIF>

<CFIF IsDefined("url.delete") AND NOT isDefined("url.batch")>
	<CFIF lcase(accessDelete) EQ "y">
		<CFIF NOT(GetEntry.RecordCount)>
			<CFSET client.xxx = "1">
			<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">

		</CFIF>

		<CFIF (lcase(GetEntry.APPROVED) EQ "y") OR lcase(GetEntry.APPROVED) EQ "C">
			<CFSET client.xxx = "2">
			<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
		</CFIF>
	<CFELSE>
		<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
	</CFIF>
</CFIF>

<CFIF IsDefined("url.copytoeform")>
	<CFIF GetForm.COPYTOFORMCODE IS NOT "">
		<CFIF NOT(GetEntry.RecordCount)>
			<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
		</CFIF>

		<CFIF lcase(GetEntry.APPROVED) EQ "y" OR lcase(GetEntry.APPROVED) EQ "C">
			<CFQUERY NAME="qryCopyToeForm" DATASOURCE=#client.company_dsn#>
				SELECT DESCRIPTION
				FROM ECRGFORMS
				WHERE FORMCODE = '#GetForm.COPYTOFORMCODE#'
			</CFQUERY>

			<CFIF NOT qryCopyToeForm.RecordCount>
				<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
			</CFIF>
		<CFELSE>
			<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
		</CFIF>
	<CFELSE>
		<CFMODULE TEMPLATE="#client.common_path#cfm_error.cfm" MODULE="#session.tabid#" TYPE="ILLEGAL">
	</CFIF>
</CFIF>
<!--- End --->

<!--- delete records --->
<CFIF ParameterExists(url.delete)  AND NOT isDefined("url.batch")>
	<CFSET sAuditAction="D">
	<CFSET qryAuditFields=GetFields>
	<CFSET sAuditTablename=eform.tablename>
	<CFSET sAuditTableLevel=GetLevelID.LEVELID>
	<CFQUERY NAME="qryAuditGetOldValue" DATASOURCE="#table_dsn#">
		SELECT *
		FROM #eform.tablename#
		WHERE
			(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
			<CFLOOP  INDEX="x" FROM="1" TO="5">
				<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
					<CFSET theVal = evaluate("url." & evaluate("GetForm.PK_FIELD" & x))>
					AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
				</CFIF>
			</CFLOOP>
    </CFQUERY>
    	<CFSET myColType=GetFields.COLUMNTYPE>
	<CFINCLUDE TEMPLATE="_audittraildata.cfm">

	<CFQUERY NAME="DeleteRecords" DATASOURCE="#table_dsn#">
		DELETE
		FROM #eform.tablename#
		WHERE
			(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
			<CFLOOP  INDEX="x" FROM="1" TO="5">
				<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
					<CFSET theVal = evaluate("url." & evaluate("GetForm.PK_FIELD" & x))>
					AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
				</CFIF>
			</CFLOOP>
	</CFQUERY>
	<CFSET sTables="#QuotedValueList(GetFormDetails.DETAILTABLE)#">
	<CFINCLUDE TEMPLATE="../common/delete_infocards.cfm">

	<CFSET sMess = "Record successfully deleted.<BR>">

	<!--- delete associated attachments --->
	<CFIF UCase(Getform.ENABLEATTACHMENTS) IS "Y" AND
		IsDefined("GetEntry.ATTACHMENTCODE") AND
		GetEntry.ATTACHMENTCODE NEQ "">
		<CFQUERY NAME="qryECINFORMSATTACH" DATASOURCE=#client.company_dsn#>
			SELECT *
			FROM ECINFORMSATTACH
			WHERE ATTACHMENTCODE = '#GetEntry.ATTACHMENTCODE#'
		</CFQUERY>

		<CFOUTPUT QUERY="qryECINFORMSATTACH">
			<CFTRY>
				<CFFILE ACTION="DELETE" FILE="#ExpandPath(client.attachment_path)##qryECINFORMSATTACH.ATTACHFILECODE#.#ListLast(qryECINFORMSATTACH.DESCRIPTION, '.')#">
			<CFCATCH>
				<!--- do nothing --->
			</CFCATCH>
			</CFTRY>
		</CFOUTPUT>

		<CFQUERY NAME="DeleteRecords" DATASOURCE="#table_dsn#">
			DELETE FROM ECINFORMSATTACH
			WHERE ATTACHMENTCODE = '#GetEntry.ATTACHMENTCODE#'
		</CFQUERY>
	</CFIF>
</CFIF>

<!--- validate values before saving record --->
<CFSET sEditMess = "">
<CFIF isDefined("Form.Save")>
	<CFLOOP INDEX="x" FROM=1 TO=#arraylen(eform.fieldsarray)#>
		<CFIF #lcase(eform.fieldsarray[x][5])# EQ "y">
			<CFIF evaluate("Form.edt" & eform.fieldsarray[x][1]) EQ "">
				<CFSET sEditMess = sEditMess & "<li>#eform.fieldsarray[x][2]# required.</li>">
			</CFIF>

		</CFIF>
	</CFLOOP>

	<CFLOOP LIST="#sListPrimary#" INDEX="x">
		<CFIF evaluate("Form.edt#x#") EQ "">
			<CFSET sEditMess = sEditMess & "<li>#x# required.</li>">
		</CFIF>
	</CFLOOP>
</CFIF>

<!---<CFINCLUDE TEMPLATE="#client.common_path#validate_format.cfm">--->
<!--- save changes and insertions --->
<CFIF (IsDefined("Form.Save") AND Form.Save NEQ "Replicate" OR IsDefined("form.savemail")) AND sEditMess EQ "" >
	<CFQUERY NAME="GetEntry" DATASOURCE="#table_dsn#" MAXROWS=1>
	SELECT *
		FROM #GetForm.TABLENAME_FK#
		WHERE
			(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
			<CFLOOP  INDEX="x" FROM="1" TO="5">
			<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "" AND IsDefined("url." & #evaluate("GetForm.PK_FIELD" & x)#)>
				<CFSET theVal = evaluate("url." & evaluate("GetForm.PK_FIELD" & x))>
				AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
			</CFIF>
			</CFLOOP>
	</CFQUERY>
	<CFSET sAttachMentCode = "#GetEntry.ATTACHMENTCODE#">
	<CFINCLUDE TEMPLATE="_savedata.cfm">
</CFIF>
<!--- Added by Maan 06282007 === get original state of form  --->
<CFIF (IsDefined("Form.Save") AND Form.Save EQ "Replicate" OR IsDefined("form.savemail")) AND sEditMess EQ "">
	<CFQUERY NAME="GetEntry" DATASOURCE="#table_dsn#" MAXROWS=1>
	SELECT *
		FROM #GetForm.TABLENAME_FK#
		WHERE
			(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
			<CFLOOP  INDEX="x" FROM="1" TO="5">
			<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "" AND IsDefined("edt" & #evaluate("GetForm.PK_FIELD" & x)#)>
				<CFSET theVal = evaluate("edt" & evaluate("GetForm.PK_FIELD" & x))>
				AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
			</CFIF>
			</CFLOOP>
	</CFQUERY>
	<CFSET sAttachMentCode = "#GetEntry.ATTACHMENTCODE#">
	<CFIF NOT isDefined("form.savemail")><!--- Condition added by Maan 09262007 ---> 
		<CFINCLUDE TEMPLATE="_savedata.cfm">
	</CFIF>
</CFIF>
<!--- Added by Mhel --->
<!--- Start --->
<CFIF isDefined("Form.Send") AND client.mailserver IS "">
	<CFINCLUDE TEMPLATE="#client.common_path#sendtoSMTP.cfm">
</CFIF>
<!--- End --->

<!--- formflow routine --->
<CFIF isDefined("Form.Route") AND sEditMess EQ "" AND client.mailserver IS "" OR ISDEFINED("FORM.btnGrpRoute")>
	<cfset myUID = GetUserInfo.USERID>
	<CFINCLUDE TEMPLATE="_saveroute.cfm">
</CFIF>

<!--- formflow routine for MAPI --->
<CFIF isDefined("Form.Route") AND sEditMess EQ "" AND client.mailserver NEQ "">
	<CFINCLUDE TEMPLATE="_saverouteMAPI.cfm">
</CFIF>

<!--- Added by Mhel for master-detail --->
<CFSET lLoadContainer=false>
<CFIF GetForm.MASTERDETAIL IS "Y">
	<CFIF ParameterExists(url.replicate)>
		<CFIF #lcase(accessAdd)# NEQ "y">
			<CFSET lLoadContainer=true>
		</CFIF>
	<CFELSEIF ParameterExists(url.edit)>
		<CFIF #lcase(accessEdit)# NEQ "y">
			<CFSET lLoadContainer=true>
		</CFIF>
	<CFELSE>
		<CFSET lLoadContainer=true>
	</CFIF>
</CFIF>

<CFSET lstFileAttachCode="">
<CFIF (IsDefined("url.sendasemail") OR IsDefined("form.savemail")) AND
		UCase(Getform.ENABLEATTACHMENTS) IS "Y">

	<CFIF IsDefined("sAttachMentCode") AND
			#sAttachMentCode# NEQ "">

		<CFQUERY NAME="qryECINFORMSATTACH" DATASOURCE=#client.company_dsn#>
			SELECT *
			FROM ECINFORMSATTACH
			WHERE ATTACHMENTCODE = '#sAttachMentCode#'
		</CFQUERY>

		<CFOUTPUT QUERY="qryECINFORMSATTACH">
			<CFSET lstFileAttachCode=lstFileAttachCode & qryECINFORMSATTACH.ATTACHFILECODE & ",">
		</CFOUTPUT>
	</CFIF>
</CFIF>

<CFSETTING ENABLECFOUTPUTONLY="No">

<cfset cfColAppBody  = "">
<cfset cfColAppTitle = "">

<CFINCLUDE TEMPLATE="#client.common_path#_toggle.cfm">
<HTML>
<HEAD>
	<TITLE>iBOS/e WebShell</TITLE>
	<CFOUTPUT>
	<LINK REL="StyleSheet" HREF="#client.wstheme_path##client.empcolor#.css" TYPE="text/css">
	<script language="javascript" src="#client.common_path#clientsides/ajax.js"></script>
	
	<!--- Removed last 05-24-2011 by Alven M. Alinan --->
	<!--- <CFINCLUDE TEMPLATE="#client.common_path#popdate.cfm"> --->
	
	
	<!--- Added last 05-24-2011 by Alven M. Alinan --->
	<cfif structKeyExists(Client, "color_appbody")>
		<cfset cfColAppBody  = client.color_appbody>
		<cfset cfColAppTitle = client.color_apptitle>
	<cfelse>
		<cfset cfColAppBody  = site_centerbodycolor>
		<cfset cfColAppTitle = site_lefthead>
	</cfif>
	
	<!--- 
			added by Alven M. Alinan 2011-06-27 
			for parameters in ajax data manipulation
	--->
	
	
	<!--- 
			Added last 05-24-2011 by Alven M. Alinan
			Converted the script from 'popdate.cfm' to 'js_popdate.js'
	 --->
	<script language="javascript1.3" src="#client.common_path#js_popdate.js"></script>
	
	
	<script language="JavaScript1.2" src="#client.common_path#CheckDate.js"></script>
	<script language="JavaScript1.2" src="#client.common_path#CheckDigit.js"></script>
	<script language="JavaScript1.2" src="#client.common_path#CheckValue.js"></script>
	<script language="JavaScript1.2" src="#client.common_path#mask.js"></script>
	<script language="JavaScript1.2" src="#client.common_path#js_currency.js"></script>
	</CFOUTPUT>
	<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
	<!--
	function PrintWindow(sURL) {
		window.open("printwindow.cfm?" + sURL,
					"PrintWindow", "width=700,height=530,ScrollBars=Yes,Resizable=Yes");
	}


	function confirmThis(message) {
		if(confirm(message)) return true;
			return false;
	}
	function ShowCalendar(FormName, FieldName, ColAppBody, ColAppTitle) {
		/* 
			added by Alven M. Alinan
			2011-05-24
			added Parameters -- ColAppBody and ColAppTitle
			pre-validation of these params are found in index.cfm of the same directory
		*/		
		quickpopdate(FormName, FieldName, ColAppBody, ColAppTitle)
	}
	function ShowLookup(level, tblname, frmfldcode, formname, fld2disp, fldcode, frmflddesc, flddesc, fldFilter, fldVal) {
		<CFOUTPUT>
			open("#client.common_path#poplookup.cfm" +
		</CFOUTPUT>
			"?tl=" + level +
			"&tn=" + tblname +
			"&fn=" + frmfldcode +
			"&frm=" + formname +
			"&fldprop=" + fld2disp +
			"&fldfn=" + fldcode +
			"&desc=" + frmflddesc +
			"&flddesc=" + flddesc +
			"&fldFilter=" + fldFilter +
			"&fldVal=" + fldVal +
			"&fldFilter=" + fldFilter +
			"&fldVal=" + fldVal,
			"LookupWindow", "width=660,height=330,ScrollBars=Yes,Resizable=Yes")
	}
	function ShowChart(level, tblname, lookupkey, desc, fld, frm, columndesc) {
	var sValue

		if (frm == '')
			sValue=fld
		else
			sValue=eval("document." + frm + "." + fld + ".value")

			open("../common/showchart.cfm" +
			"?levelid=" + level +
			"&table=" + tblname +
			"&lkupkeycode=" + lookupkey +
			"&desc=" + desc +
			"&value=" + sValue +
			"&columndesc=" + columndesc,
			"LookupWindow", "width=660,height=330,ScrollBars=Yes,Resizable=Yes")
	}

	function GetValue(level, tblname, frmfldcode, formname, fld2disp, fldcode, frmflddesc, flddesc,fldFilter, fldVal,svalue) {

		if (svalue != "")
			<CFOUTPUT>
			    open("#client.common_path#locate.cfm" +
				"?tl=" + level +
				"&tn=" + tblname +
				"&fn=" + frmfldcode +
				"&frm=" + formname +
				"&fldprop=" + fld2disp +
				"&fldfn=" + fldcode +
				"&desc=" + frmflddesc +
				"&flddesc=" + flddesc +
				"&fldFilter=" + fldFilter +
				"&fldVal=" + fldVal +
				"&svalue=" + svalue,
				"LookupWindow", "width=660,height=330,ScrollBars=No,Resizable=No,Left=5000")
			</CFOUTPUT>
	}

	//-->
	</SCRIPT>
</HEAD>

<BODY TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0
	<CFIF lLoadContainer>onunload="if ((typeof eFormHandle) != 'undefined') {eFormHandle.close()}"</CFIF>>
	<CFMODULE TEMPLATE="#client.common_path#cfm_workspace.cfm" MODULE="#session.tabId#" LOCATION="#session.tabLocation#" COMPONENT="#GetForm.DESCRIPTION#">
	<CFSETTING ENABLECFOUTPUTONLY="Yes">
	<CFQUERY NAME="IsValidTemplate" DATASOURCE="#client.global_dsn#">
		SELECT COLUMNNAME
		FROM GRGBOSETABLEFIELDS
		WHERE
			(COLUMNNAME = 'PERSONNELIDNO') AND
			(TABLENAME  = '#GetForm.TABLENAME_FK#')
	</CFQUERY>
	<CFSETTING ENABLECFOUTPUTONLY="No">
	<CFIF NOT(IsValidTemplate.RecordCount)>
		<BR><BR>
		<H3>Invalid template.</H3>
		<CFOUTPUT>
		This template requires field 'PersonnelIDNo' to exist in the table.<BR>
		Please notify your iBOS/e Administrator.
		</CFOUTPUT>
		<CFMODULE TEMPLATE="#client.common_path#cfm_workspace.cfm" TOP="False">
		<CFABORT>
	</CFIF>
	<CFIF sEditMess NEQ "">
		<CFOUTPUT>
			<CFMODULE TEMPLATE="#client.common_path#cfm_wswindow.cfm" TITLE="iBOS/e eForms">
			<H4>Problems encountered:</H4>
			#sEditMess#<BR><BR>
			<A HREF="javascript: history.back();">Back to Edit Screen</A><BR><BR>
			<CFMODULE TEMPLATE="#client.common_path#cfm_wswindow.cfm" TOP="False">
			<CFMODULE TEMPLATE="#client.common_path#cfm_workspace.cfm" TOP="False">
		</CFOUTPUT>
		<CFABORT>
	</CFIF>
	
	
	<!--- commented by Alven M. Alinan --->
	<!--- start of enhancing the UI (2011-06-27) --->
	
	
	<CFIF ParameterExists(url.alttaskid)>
		<!--- this is accessed using the calendar --->
		<CFINCLUDE TEMPLATE="_quickedit.cfm">
	<CFELSE>
		<!--- Added by jEPOY --->
		<!--- Start --->
		<CFIF isDefined("Form.brnGrpRoute") or isDefined("url.grproute")>
			<CFINCLUDE TEMPLATE="grouproute.cfm">
		<CFELSEIF isDefined("Form.btnBatch") or isDefined("url.batch")>
			<CFINCLUDE TEMPLATE="batchAppMain.cfm">
		<!--- End --->
		<!--- normal access --->
		<CFELSEIF isDefined("Form.Add")>
			<CFINCLUDE TEMPLATE="editform.cfm">
		<CFELSEIF ParameterExists(url.replicate)>
			<CFIF #lcase(accessAdd)# EQ "y">
				<CFINCLUDE TEMPLATE="editform.cfm">
			<CFELSE>
				No right to add a new record.
				<CFINCLUDE TEMPLATE="verifysubcompany.cfm">
			</CFIF>
		
		<CFELSEIF ParameterExists(url.view)>
			<CFINCLUDE TEMPLATE="viewform.cfm">
		<CFELSEIF ParameterExists(url.edit)>
			<CFIF #lcase(accessEdit)# EQ "y">
				<CFIF(Trim(GetForm.PROCESSCODE) NEQ "" AND IsDefined("GetEntry.ROUTEID")) AND GetForm.MULTIPLEFORMFLOW EQ "Y" AND NOT ISDEFINED("FORM.btnnewFormFlow") and not isdefined("url.updateflow")>
					<CFINCLUDE TEMPLATE="../common/multipleformflow.cfm">
				<CFELSE>
					<CFINCLUDE TEMPLATE="editform.cfm">
				</CFIF>
			<CFELSE>
				No right to edit records.
				<CFINCLUDE TEMPLATE="verifysubcompany.cfm">
			</CFIF>
		<CFELSEIF ISDEFINED("FORM.btnnewFormFlow")>
			<CFIF #lcase(accessEdit)# EQ "y">
				<CFINCLUDE TEMPLATE="editform.cfm">
			<CFELSE>
				No right to edit records.
				<CFINCLUDE TEMPLATE="verifysubcompany.cfm">
			</CFIF>
		<CFELSEIF ParameterExists(url.sendasemail)>
			<CFINCLUDE TEMPLATE="getformbody.cfm">
			<CFINCLUDE TEMPLATE="#client.common_path#sendasemail.cfm">
		<CFELSEIF ParameterExists(url.copytoeform)>
			<CFINCLUDE TEMPLATE="copytoeform.cfm">
		<CFELSEIF IsDefined("form.savemail")>
			<!--- save and email form --->
			<CFINCLUDE TEMPLATE="getformbody.cfm">
			<CFINCLUDE TEMPLATE="#client.common_path#sendasemail.cfm">
		<CFELSE>
			<CFINCLUDE TEMPLATE="verifysubcompany.cfm">
		</CFIF>
	</CFIF>
	
	<!---  added by Alven M. Alinan 2011-06-27 --->
	<!---  viewform, editform will be on client side request and response --->
	<CFMODULE TEMPLATE="#client.common_path#cfm_wswindow.cfm" TITLE="Master View">
		<span id="window_view"></span>
	<CFMODULE TEMPLATE="#client.common_path#cfm_wswindow.cfm" TOP="false">
		
	<CFMODULE TEMPLATE="#client.common_path#cfm_workspace.cfm" TOP="False">
	
	
	
</BODY>
</HTML>